package hyperlinks.crawler;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.util.LinkedList;

/**
 *
 * @author madhu
 */
public class URLQueue {
	private LinkedList list;
	
	// URLQueue constructor
	public URLQueue()
	{
		// Create a new LinkedList.
		list = new LinkedList();
	}

	public boolean isEmpty()
	// Post: Returns true if the queue is empty. Otherwise, false.
	{
		return (list.size() == 0);
	}

	public void enqueue(Object item)
	// Post: An item is added to the back of the queue.
	{
		// Append the item to the end of our linked list.
		list.addLast(item);
	}

	public Object dequeue()
	{
		
		Object item = list.getFirst();
		list.removeFirst();
		// Return the item
		return item;
	}

	public Object peek()
	{
		// This method is very similar to dequeue(). but without removing item
		// See URLQueue.dequeue() for comments.
		return list.get(1);
	}
        
    void printQueue(URLQueue urlqueue) {
        System.out.println(list);
       }

    int size() {
        return list.size();
    }

    void clear() {
        list.clear();
    }

    boolean hasThis(String tobefetched) {
        // if this function returns true means that the url tobefetchd is already fetched
       return list.contains(tobefetched);
    }
}